package com.bt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bt.mapper.DtsGoodsAttributeMapper;
import com.bt.pojo.DtsGoodsAttribute;
import com.bt.service.DtsGoodsAttributeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wbt
 * @version v1.0
 * @project shop_manage
 * @data 2022/9/23 15:44
 **/
@Service
public class DtsGoodsAttributeServiceImpl implements DtsGoodsAttributeService {
    @Autowired
    private DtsGoodsAttributeMapper dtsGoodsAttributeMapper;
    @Override
    public List<DtsGoodsAttribute> findDtsGoodsAttributeByGoodsId(Integer id) {
        return dtsGoodsAttributeMapper.selectList(new QueryWrapper<DtsGoodsAttribute>().eq(id!=null?true:false,"goods_id",id));
    }

    @Override
    public void updateGoodsAttribute(List<DtsGoodsAttribute> attributes, Integer id) {
        dtsGoodsAttributeMapper.delete(new QueryWrapper<DtsGoodsAttribute>().eq("goods_id",id));
        dtsGoodsAttributeMapper.insertBatch(attributes);
    }
    @Override
    public void insertGoodsAttribute(List<DtsGoodsAttribute> attributes) {
        dtsGoodsAttributeMapper.insertBatch(attributes);
    }

    @Override
    public void deleteGoodsAttributeByGoodsId(Integer id) {
        dtsGoodsAttributeMapper.delete(new QueryWrapper<DtsGoodsAttribute>().eq("goods_id",id));
    }
}
